package gamecode;

import java.util.ArrayList;
import java.util.List;

import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Rectangle;

public class EntityManager {

	private List<Entity> entities;
	
	public EntityManager() {
		entities = new ArrayList<Entity>();
	}
	
	public void addEntity(Entity e) {
		entities.add(e);
	}
	
	public boolean removeEntity(Entity e) {
		return entities.remove(e);
	}
	
	public void drawEntities(Graphics g, Rectangle bounds, EntityPlayerShip player) {
		for (Entity e : entities) {
			try {
				if(e.isPlayerShip) {
					EntityPlayerShip.class.cast(e).drawShip(g, bounds);
				}
				else {
					e.drawEntity(g, bounds, player);
				}
			}
			catch (Exception ex) {
				System.out.println("Error drawing an entity: " + ex.getMessage());
			}
		}
	}
	
	public void clear() {
		entities.clear();
	}
}
